package com.miaosha.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miaosha.entity.Order;
import com.miaosha.entity.dto.OrderSetStatusReqDto;
import com.miaosha.entity.dto.SellerListResDto;
import com.miaosha.mapper.OrderMapper;
import com.miaosha.service.OrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("orderService")
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Resource
    private OrderMapper orderMapper;

    @Override
    public List<Order> list(Map<String, Object> map) {
        return orderMapper.list(map);
    }

    @Override
    public int update(Order order) {
        return orderMapper.updateById(order);
    }

    @Override
    public Order findById(Integer id) {
        return orderMapper.selectById(id);
    }

    @Override
    public Order findByUserIdAndMiaoShaGoodsId(Map<String, Object> map) {
        return orderMapper.findByUserIdAndMiaoShaGoodsId(map);
    }

    @Override
    public void setStatus(OrderSetStatusReqDto orderSetStatusReqDto) {
        Order order = new Order();
        order.setId(orderSetStatusReqDto.getOrder_id());
        order.setPayStatus(orderSetStatusReqDto.getStatus());
        orderMapper.updateById(order);
    }

    @Override
    public List<SellerListResDto> sellerList(Long userId) {
        List<SellerListResDto> result = orderMapper.sellerList(userId);
        return result;
    }
}
